<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图 -->
    <el-card>
      <!-- 搜索区域 -->
      <el-row>
        <el-col class="col-item" :span="8">
          <el-input placeholder="请输入内容" class="input-with-select">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表格 -->
      <el-table border :data="orderList" size="small">
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column prop="order_number" label="订单标号"></el-table-column>
        <el-table-column prop="order_price" label="订单价格"></el-table-column>
        <el-table-column prop="pay_status" label="是否付款">
          <template slot-scope="scope">
           <el-tag type="danger" v-if="scope.row.pay_status==0">未付款</el-tag>
            <el-tag type="success" v-if="scope.row.pay_status==1">已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"></el-table-column>
        <el-table-column prop="create_time" label="下单时间">
          <template slot-scope="scope">
            {{scope.row.create_time|dateFormat}}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button @click="dialogVisible=true" size="mini" type="primary" icon="el-icon-edit"></el-button>
            <el-button @click="wuliuBox(scope.row.order_id)" size="mini" type="primary" icon="el-icon-location"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[3, 5, 10, 15]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="nowtotal">
      </el-pagination>
    </el-card>
    <!-- 修改地址的对话框 -->
    <el-dialog title="提示" :visible.sync="dialogVisible" width="50%" @close="clearForm">
      <el-form :model="addressForm" :rules="addressrule" ref="addressForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="省/市区" prop="address1">
          <!-- 省市级联选择器 -->
          <el-cascader
            v-model="addressForm.address1"
            :options="citydata"
            expand-Trigger="hover"
            @change="handleChange">
          </el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="addressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 物流信息对话框 -->
    <el-dialog title="物流信息" :visible.sync="wuliuBoxVisible" width="50%" @close="clearForm">
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import{orderList,kuaidiMessage}from '@/api/login'
import citydata from './citydata'
export default {
  data(){
    return{
      queryInfo: {
        query: '',
        pagenum:1,
        pagesize:5
      },
      // 订单列表
      orderList:[],
      // 总页数
      nowtotal:null,
      // 对话框
      dialogVisible:false,
      // 物流对话框
      wuliuBoxVisible:false,
      // 省市区
      addressForm:{
        address1:[],
        address2:""
      },
      // 地址的表单验证
      addressrule:{
        address1: [
          { required: true, message: '请输入省市区', trigger: 'blur' },
        ],
         address2: [
          { required: true, message: '请输入详细地址', trigger: 'blur' },
        ],
      },
      // 城市信息
      citydata
    }
  },
  created(){
    this.loadData()
  },
  methods:{
    // 初始数据
    loadData(){
      const{query,pagenum,pagesize}=this.queryInfo
      orderList({query,pagenum,pagesize}).then(({data})=>{
        console.log(data)
        this.orderList=data.data.goods
        this.nowtotal=data.data.total
      })
    },
    // 页码数改变事件
    handleCurrentChange(pagenum){
      console.log(pagenum)
      this.queryInfo.pagenum=pagenum
      this.loadData()
    },
    // 页面展示条数改变事件
    handleSizeChange(pagesize){
      console.log(pagesize)
       this.queryInfo.pagesize=pagesize
       this.loadData()
    },
    // 关闭对话框，重置表单
    clearForm() {
      this.$refs.addressForm.resetFields();
    },
    // 级联选择器选中的城市id(数组)
    handleChange(Arry){
      console.log(Arry)
      this.addressForm.address1=Arry
    },
    // 物流信息展示
    wuliuBox(Id){
      this.wuliuBoxVisible=true
      kuaidiMessage('/kuaidi/1106975712662').then(res=>{
        console.log(res)
      })
    }
  }
}
</script>
<style Lang="less" scoped>

</style>